<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>
<h1 align="center">添加学生</h1>
<form id="addForm" method="post">
    <table id="abc" align="center">
        <tr>
            <td>姓名</td>
            <td><input name="name"></td>
        </tr>
        <tr>
            <td>性别</td>
            <td><input name="gender"></td>
        </tr>
        <tr>
            <td>年龄</td>
            <td><input name="age"></td>
        </tr>
        <tr>
            <td>电话</td>
            <td><input name="telephone"></td>
        </tr>
        <tr>
            <td>邮箱</td>
            <td><input name="email"></td>
        </tr>
        <tr>
            <td>班级</td>
            <td>
                <select  id="a" name="cid">
                    <option>请选择</option>
                </select>
            </td>
        </tr>
    </table>
    <center>
        <button type="reset">重置</button>
        <input  type="button" value="提交" onclick="tj()">
        <button>返回</button>
    </center>

</form>
<script>
$(function () {
    $.ajax({
        url:"/student/gettypes",
        type:"post",
        datatype:"json",
        success:function (data) {
            $.each(data,function (index,obj) {
                var html = $("<option></option>").val(obj.cid).html(obj.cname);
                $("#a").append(html)

            })

        }
    })
})
    function tj(){
        var data1 = $("#addForm").serialize();
        $.ajax({
            url:"/student/addstu",
            type:"post",
            datatype:"json",
            data:data1,
            success:function(data){
                if(data.flag){
                    location.href="index.html";
                }
            }
        })

    }


</script>
</body>
</html>